const ora = require('ora')
const { exec } = require('child_process')
const chalk = require('chalk')

let script = 'vue-cli-service build'
let env = process.argv[2] || ''
if (process.argv[2] && env != 'prod') {
    script += ' --mode ' + env
}

console.log(chalk.magenta('_|      _|  _|_|_|    _|_|      _|_|  '));
console.log(chalk.magenta('_|_|  _|_|    _|    _|    _|  _|    _|'));
console.log(chalk.magenta(`_|  _|  _|    _|    _|_|_|_|  _|    _|`));
console.log(chalk.magenta('_|      _|    _|    _|    _|  _|    _|'));
console.log(chalk.magenta('_|      _|  _|_|_|  _|    _|    _|_|  '));
console.log('\n');
const spinner = ora(`Building for ${env || 'prod'}...`)
spinner.start()

exec(script, (error, stdout) => {
    if (error) {
        console.log(chalk.red(`[error]: ${error}`))
        return
    }
    console.log('\n')
    console.log(stdout)
    spinner.stop()
})